//数量金额余额表动态列

var columns = function(mode){
    var cols = [{
        title:'科目编码',
        field:'buname',
        align:'left',
        width:100,
        className:'bdr'
    }, {
        title:'科目名称',
        field:'buname',
        width:'auto'
    }, {
        title:'单位',
        field:'buname',
        width:'110',
        className:'bdl',
        children:null
    }];

    //数量外币式
    if(mode == '1'){
        cols = cols.concat([
            {
                title:'期初余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'单价',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'借方外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'贷方外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'本期发生额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'入库数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'入库金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'出库数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'出库金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'期末余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'单价',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'借方外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'贷方外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }
        ])
    }

    //数量金额式
    else{
        cols = cols.concat([
            {
                title:'期初余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'单价',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'借方金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'贷方金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'本期发生额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'入库数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr',
                    nowrap:true
                }, {
                    title:'入库金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'出库数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'出库金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'期末余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'单价',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'借方金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'贷方金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }
        ])
    }

    var count = 0, width;
    Nui.each(cols, function(v){
        if(v && v.children){
            count++
        }
    })

    if(count === 3){
        width = 24
    }
    else if(count === 4){
        
    }

    var _cols = [];
    Nui.each(cols, function(v){
        if(v){
            if(v.children){
                v.width = width+'%';
                Nui.each(v.children, function(_v){
                    _v.width = width/4 + '%';
                })
            }
            _cols.push(v)
        }
    })

    return _cols
}

return columns